<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="artDialog/skins/default.css"
	type="text/css"></link>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="artDialog/artDialog.min.js"></script>
<script type="text/javascript" src="artDialog/jquery.artDialog.min.js"></script>
<script type="text/javascript" src="artDialog/artDialog.plugins.min.js"></script>
<script type="text/javascript" src="js/util.js"></script>

<script type="text/javascript">
$(document).ready(function(){
  $(".click").click(function(){
  $(".tip").fadeIn(200);
  });
  
  $(".tiptop a").click(function(){
  $(".tip").fadeOut(200);
});

  $(".sure").click(function(){
  $(".tip").fadeOut(100);
});

  $(".cancel").click(function(){
  $(".tip").fadeOut(100);
});
$.post("bugType!findList.action",function(data){
	var bts = eval("("+data+")");
	if(bts!=null){
	var html = "";

		for(var i = 0 ; i < bts.length;i++){
			html+="<tr><td><input name=\"checkboxBtn\" onclick=\"oneClick(this)\" value="+bts[i].id+" type=\"checkbox\" /></td><td>"+bts[i].id+"</td><td>"+bts[i].name+"</td><td>"+(bts[i].state==1? "正常":"停用")+"</td><td><a href=\"javascript:void(0)\" onclick='bugtype_update("+bts[i].id+",\""+bts[i].name+"\")' >修改</a>     <a href=\"javascript:void(0)\" onclick='bugtype_del("+bts[i].id+")' >删除</a></td></tr>";
		}
		$("#bugtype_list").html(html);
		$('#bugtype_list tr:odd').addClass('odd');
		
	}
});
});

function bugtype_del(id){
	okCancelAlert("删除缺陷类型","确定删除此缺陷类型?",function(){
		$.post("bugType!deleteBugType.action",{bid:id},function(data){
			var json = eval("("+data+")");
			
			if(json.code==1){
				defaultAlert("删除缺陷类型","删除成功");
				location.href="bugtype.html";
			}else if(json.code==0){
				defaultAlert("删除缺陷类型","已分配类型");
			}else{
				defaultAlert("删除缺陷类型","未知错误");
			}
		});
	},function(){});}
function bugtype_update(id,name){
	art.dialog({title:"修改缺陷类型名称",content:"<input class='dfinput' type='text' id='in_type_name' value='"+name+"' />",lock:true,fixed:true,okValue:'修改',cancelValue:'取消',ok:function(){
		var tname = document.getElementById("in_type_name");
		if(tname.value==""){
			tname.select();
			tname.focus();
			this.shake();
			return false;
		}
		$.post("bugType!updateName.action",{"bugtype.id":id,"bugtype.name":tname.value},function(data){
			var json = eval("("+data+")");
			if(json.code==1){
				defaultAlert("修改缺陷类型名称","修改成功");
				location.href="bugtype.html";
			}else{
				defaultAlert("修改缺陷类型名称","已分配类型");
			}
		});
	},cancel:function(){}});
}

function type_add(){
		var html ="<input type='text' class='dfinput' id='add_bug_name'/>"
		art.dialog({title:"缺陷类型添加",lock:true,fixed:true,content:html,okValue:"添加",cancelValue:"取消",cancel:function(){},ok:function(){
				var name = document.getElementById("add_bug_name");
				if(name.value==""){
					name.select();
					name.focus();
					this.shake();
					return false;
				}
				$.post("bugType!addBugType.action",{"bugtype.name" : name.value,"bugtype.state":1},function(data){
					var json = eval("("+data+")");
					if(json.code==1){
						defaultAlert("缺陷类型添加","添加成功");
						setTimeout(function () { location.href="bugtype.html"; }, 1000);
					}else{
						defaultAlert("缺陷类型添加","添加失败");
					}
				});
			
			}
		});
}

function allClick() {
	var checkbox = document.getElementsByName("checkboxBtn"); 
	var box= document.getElementById("selectAll");
	for(var i=0;i<checkbox.length;i++){
		if(box.checked === true){
		   	checkbox[i].checked = true;
		}else{
			checkbox[i].checked = false;
		}
	}
}
function oneClick(va){
	var checkbox = document.getElementsByName("checkboxBtn");
	var box= document.getElementById("selectAll");
	var checked_counts = 0;
	for(var i=0;i<checkbox.length;i++){
		if(checkbox[i].checked){
			checked_counts++;
		};
	};
	if(checkbox.length==checked_counts){
		box.checked = true;
	}else{
		box.checked = false;
	}
};	
function del_check() {
	obj = document.getElementsByName("checkboxBtn");
	var check_val = "";
	n = 0;
    for(k in obj){
        if(obj[k].checked)
        	check_val+=obj[k].value+",";
    }
    /* 
    	判断选中复选框的个数
     */
    for ( i = 0; i < obj.length; i++) {
		if(obj[i].checked)
        	n++;
	}
	if(n!=0){
	    okCancelAlert("删除缺陷类型","确定删除所选缺陷类型?",function(){
			$.post("bugType!deleteBugTypeByAll.action",{"numsIdList":check_val},function(data){
				var json = eval("("+data+")");
				if(json.code==1){
					defaultAlert("删除缺陷类型","删除成功");
					location.href="bugtype.html";
				}else if(json.code==0){
					defaultAlert("删除缺陷类型","删除失败");
				}else{
					defaultAlert("删除缺陷类型","未知错误");
				}
			});
		},function(){});
	}
    
}
</script>


</head>


<body>

	<div class="place">
    <span>位置：</span>
    <ul class="placeul">
    <li><a href="#">首页</a></li>
    <li><a href="#">缺陷管理</a></li>
    <li><a href="#">缺陷类型设置</a></li>
    </ul>
    </div>
    
    <div class="rightinfo">
    
    <div class="tools">
    
    	<ul class="toolbar">
        <li onclick="type_add()"><span><img src="images/t01.png" /></span>添加</li>
    <!--     <li class="click"><span><img src="images/t02.png" /></span>修改</li> -->
        <li onclick="del_check()"><span><img src="images/t03.png" /></span>删除</li>
      <!--   <li><span><img src="images/t04.png" /></span>统计</li> -->
        </ul>
        
        
        <ul class="toolbar1">
        <!-- <li><span><img src="images/t05.png" /></span>设置</li> -->
        </ul>
    
    </div>
    
    
    <table class="tablelist">
    	<thead>
    	<tr>
        <th><input  onclick="allClick()" id="selectAll" type="checkbox"/></th>
        <th>编号<i class="sort"><img src="images/px.gif" /></i></th>
        <th>名称</th>
        <th>状态</th>
        <th>操作</th>
        </tr>
        </thead>
        <tbody id="bugtype_list">
       
        </tbody>
    </table>
   
    <script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');
	</script>

</body>
</html>
